package com.dfch.auto.appium.main;

import com.dfch.auto.appium.app.AutoApp;
import com.dfch.auto.appium.app.AutoAppFactory;
import com.dfch.auto.appium.bean.AutoParamBean;
import com.dfch.auto.appium.pool.AutoThreadPool;

import javax.swing.*;

/**
 * @author ldcmaxim on 04/04/2018.
 */
public class AutoScriptMain {
    //private static final Logger LOGGER = LoggerFactory.getLogger(AutoScriptMain.class);

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            AutoMainFrame frame = new AutoMainFrame();
            frame.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }

        /*
        if (args == null || args.length <= 0) {
            return;
        }
        String str = "{\"action\":[{\"platformVersion\":\"7.0\",\"deviceName\":\"98891a345043414c55\",\"url\":\"http://127.0.0.1:6000/wd/hub\", \"comment\":\"这首歌叫什么?\"}]}";
        AutoBean base = FastJsonUtils.getObject(args[0], AutoBean.class);
        if (base == null || base.action == null || base.action.isEmpty()) {
            return;
        }


        List<AutoParamBean> params = FastJsonUtils.getListObjects(base.action, AutoParamBean.class);
        if (params.isEmpty()) {
            return;
        }

        for (AutoParamBean param : params) {
            StartApp("Android", "DouYin", param);
        }
        */
    }

    private static void StartApp(String platform, String tag, AutoParamBean bean) {
        AutoThreadPool.getInstance().executeAsyncTask(new Runnable() {
            @Override
            public void run() {
                AutoApp app = AutoAppFactory.getAutoApp(platform, tag);
                app.init(bean.deviceName, bean.platformVersion, bean.url);
                app.execute(bean.comment, 5);
                app.release();
            }
        });
    }

}